﻿using CRMBiz;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;

namespace CRMWeb.Pages
{
    public partial class VerificationChecklist : CRMWeb.Utilities.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string appid = Request.QueryString["app_id"].ToString();
                GetVerificatioChecklistDetail(int.Parse(appid));
            }
        }
        private bool getBoolean(string value)
        {
            bool flag = false;
            if (value == "True")
                flag = true;
            return flag;
        }
        private void FillCheckboxForOneRows(DataTable dtCheckList)
        {
            hdnApplicationContactID1.Value = dtCheckList.Rows[0]["ApplicationContactID"].ToString();
            chkCenterLink1.Checked = getBoolean(dtCheckList.Rows[0]["Income_Payslip"].ToString());

            //chkbankst1.Checked = 
            chk2mnths1.Checked = getBoolean(dtCheckList.Rows[0]["Bank_LatestMonth"].ToString());
            chkFullName1.Checked = getBoolean(dtCheckList.Rows[0]["Bank_FullName"].ToString());
            chkBSB1.Checked = getBoolean(dtCheckList.Rows[0]["Bank_ACBSB"].ToString());

            if (chk2mnths1.Checked == true && chkFullName1.Checked == true && chkBSB1.Checked == true)
                chkbankst1.Checked = true;
            else
                chkbankst1.Checked = false;

            chkVehicles1.Checked = getBoolean(dtCheckList.Rows[0]["Assert_Vehicles"].ToString()); ;
            chkCouncilRate1.Checked = getBoolean(dtCheckList.Rows[0]["Assert_CouncilRate"].ToString()); ;
            chkMortage1.Checked = getBoolean(dtCheckList.Rows[0]["Assert_Mortage"].ToString()); ;
            chkValuation1.Checked = getBoolean(dtCheckList.Rows[0]["Assert_Valuation"].ToString()); ;
            chkRentalReceipt1.Checked = getBoolean(dtCheckList.Rows[0]["IDs_Residential_Rental"].ToString()); ;
            chkRate1.Checked = getBoolean(dtCheckList.Rows[0]["Residential_Rate"].ToString());
            chkBoarding1.Checked = getBoolean(dtCheckList.Rows[0]["IDs_Residential_Boarding"].ToString());
            chkBills1.Checked = getBoolean(dtCheckList.Rows[0]["IDs_UtilityBill"].ToString());
            chkPassport1.Checked = getBoolean(dtCheckList.Rows[0]["IDs_PhotoID"].ToString());
            chkCard1.Checked = getBoolean(dtCheckList.Rows[0]["IDs_Card"].ToString());

            FillExtraItem1(dtCheckList);

        }
        private void FillCheckboxForTwoRows(DataTable dtCheckList)
        {
            FillCheckboxForOneRows(dtCheckList);
            hdnApplicationContactID2.Value = dtCheckList.Rows[1]["ApplicationContactID"].ToString();

            chkCenterLink2.Checked = getBoolean(dtCheckList.Rows[1]["Income_Payslip"].ToString());

            //chkbankst2.Checked = 
            chk2mnths2.Checked = getBoolean(dtCheckList.Rows[1]["Bank_LatestMonth"].ToString());
            chkFullName2.Checked = getBoolean(dtCheckList.Rows[1]["Bank_FullName"].ToString());
            chkBSB2.Checked = getBoolean(dtCheckList.Rows[1]["Bank_ACBSB"].ToString());

            if (chk2mnths2.Checked == true && chkFullName2.Checked == true && chkBSB2.Checked == true)
                chkbankst2.Checked = true;
            else
                chkbankst2.Checked = false;

            chkVehicles2.Checked = getBoolean(dtCheckList.Rows[1]["Assert_Vehicles"].ToString()); ;
            chkCouncilRate2.Checked = getBoolean(dtCheckList.Rows[1]["Assert_CouncilRate"].ToString()); ;
            chkMortage2.Checked = getBoolean(dtCheckList.Rows[1]["Assert_Mortage"].ToString()); ;
            chkValuation2.Checked = getBoolean(dtCheckList.Rows[1]["Assert_Valuation"].ToString()); ;
            chkRentalReceipt2.Checked = getBoolean(dtCheckList.Rows[1]["IDs_Residential_Rental"].ToString()); ;
            chkRate2.Checked = getBoolean(dtCheckList.Rows[1]["Residential_Rate"].ToString());
            chkBoarding2.Checked = getBoolean(dtCheckList.Rows[1]["IDs_Residential_Boarding"].ToString());
            chkBills2.Checked = getBoolean(dtCheckList.Rows[1]["IDs_UtilityBill"].ToString());
            chkPassport2.Checked = getBoolean(dtCheckList.Rows[1]["IDs_PhotoID"].ToString());
            chkCard2.Checked = getBoolean(dtCheckList.Rows[1]["IDs_Card"].ToString());

            //FillExtraItem1(dtCheckList);
            FillExtraItem2(dtCheckList);
        }
        private void FillCheckboxForThreeRows(DataTable dtCheckList)
        {
            FillCheckboxForTwoRows(dtCheckList);
            hdnApplicationContactID3.Value = dtCheckList.Rows[2]["ApplicationContactID"].ToString();

            chkCenterLink3.Checked = getBoolean(dtCheckList.Rows[2]["Income_Payslip"].ToString());

            //chkbankst2.Checked = 
            chk2mnths3.Checked = getBoolean(dtCheckList.Rows[2]["Bank_LatestMonth"].ToString());
            chkFullName3.Checked = getBoolean(dtCheckList.Rows[2]["Bank_FullName"].ToString());
            chkBSB3.Checked = getBoolean(dtCheckList.Rows[2]["Bank_ACBSB"].ToString());

            if (chk2mnths3.Checked == true && chkFullName3.Checked == true && chkBSB3.Checked == true)
                chkbankst3.Checked = true;
            else
                chkbankst3.Checked = false;

            chkVehicles3.Checked = getBoolean(dtCheckList.Rows[2]["Assert_Vehicles"].ToString()); ;
            chkCouncilRate3.Checked = getBoolean(dtCheckList.Rows[2]["Assert_CouncilRate"].ToString()); ;
            chkMortage3.Checked = getBoolean(dtCheckList.Rows[2]["Assert_Mortage"].ToString()); ;
            chkValuation3.Checked = getBoolean(dtCheckList.Rows[2]["Assert_Valuation"].ToString()); ;
            chkRentalReceipt3.Checked = getBoolean(dtCheckList.Rows[2]["IDs_Residential_Rental"].ToString()); ;
            chkRate3.Checked = getBoolean(dtCheckList.Rows[2]["Residential_Rate"].ToString());
            chkBoarding3.Checked = getBoolean(dtCheckList.Rows[2]["IDs_Residential_Boarding"].ToString());
            chkBills3.Checked = getBoolean(dtCheckList.Rows[2]["IDs_UtilityBill"].ToString());
            chkPassport3.Checked = getBoolean(dtCheckList.Rows[2]["IDs_PhotoID"].ToString());
            chkCard3.Checked = getBoolean(dtCheckList.Rows[2]["IDs_Card"].ToString());

            FillExtraItem3(dtCheckList);
        }


        public void GetVerificatioChecklistDetail(int app_id)
        {
            DataTable dtCheckList = null;
            try
            {
                if (app_id > 0)
                {
                    dtCheckList = VerificationChecklistHandler.GetVerificationChecklistDetail(app_id);

                    if (dtCheckList.Rows.Count == 1)
                    {
                        hdntotalApplicant.Value = "1";
                        //DisableForFirstApplicant();
                        FillCheckboxForOneRows(dtCheckList);
                    }
                    else if (dtCheckList.Rows.Count == 2)
                    {
                        hdntotalApplicant.Value = "2";
                        //DisableForSecondApplicant();
                        FillCheckboxForTwoRows(dtCheckList);
                    }

                    else if (dtCheckList.Rows.Count == 3)
                    {
                        hdntotalApplicant.Value = "3";
                        FillCheckboxForThreeRows(dtCheckList);
                    }
                    else if (dtCheckList.Rows.Count == 0)
                    {
                        // New Entry for V. Checklist
                        DataSet ds = VerificationChecklistHandler.IsExistApplicationContactID(app_id);
                        if (ds.Tables[0].Rows.Count == 1)
                        {
                            hdnApplicationContactID1.Value = ds.Tables[0].Rows[0]["ApplicationcontactID"].ToString();
                            hdntotalApplicant.Value = "1";
                            //DisableForFirstApplicant();
                        }
                        else if (ds.Tables[0].Rows.Count == 2)
                        {
                            hdnApplicationContactID1.Value = ds.Tables[0].Rows[0]["ApplicationcontactID"].ToString();
                            hdnApplicationContactID2.Value = ds.Tables[0].Rows[1]["ApplicationcontactID"].ToString();
                            hdntotalApplicant.Value = "2";
                            // DisableForSecondApplicant();
                        }
                        else if (ds.Tables[0].Rows.Count >= 3)
                        {
                            hdnApplicationContactID1.Value = ds.Tables[0].Rows[0]["ApplicationcontactID"].ToString();
                            hdnApplicationContactID2.Value = ds.Tables[0].Rows[1]["ApplicationcontactID"].ToString();
                            hdnApplicationContactID3.Value = ds.Tables[0].Rows[2]["ApplicationContactID"].ToString();
                            hdntotalApplicant.Value = "3";
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        private DataTable setValueForHiddenField(DataTable dtCheckList, int rowno)
        {
            DataTable dt;

            int ExtraChecklistItemID1 = string.IsNullOrEmpty(dtCheckList.Rows[rowno]["ExtraItemNo1"].ToString()) ? 0 : int.Parse(dtCheckList.Rows[rowno]["ExtraItemNo1"].ToString());
            int ExtraChecklistItemID2 = string.IsNullOrEmpty(dtCheckList.Rows[rowno]["ExtraItemNo2"].ToString()) ? 0 : int.Parse(dtCheckList.Rows[rowno]["ExtraItemNo2"].ToString());
            int ExtraChecklistItemID3 = string.IsNullOrEmpty(dtCheckList.Rows[rowno]["ExtraItemNo3"].ToString()) ? 0 : int.Parse(dtCheckList.Rows[rowno]["ExtraItemNo3"].ToString());
            int ExtraChecklistItemID4 = string.IsNullOrEmpty(dtCheckList.Rows[rowno]["ExtraItemNo4"].ToString()) ? 0 : int.Parse(dtCheckList.Rows[rowno]["ExtraItemNo4"].ToString());
            int ExtraChecklistItemID5 = string.IsNullOrEmpty(dtCheckList.Rows[rowno]["ExtraItemNo5"].ToString()) ? 0 : int.Parse(dtCheckList.Rows[rowno]["ExtraItemNo5"].ToString());
            int ExtraChecklistItemID6 = string.IsNullOrEmpty(dtCheckList.Rows[rowno]["ExtraItemNo6"].ToString()) ? 0 : int.Parse(dtCheckList.Rows[rowno]["ExtraItemNo6"].ToString());
            int ExtraChecklistItemID7 = string.IsNullOrEmpty(dtCheckList.Rows[rowno]["ExtraItemNo7"].ToString()) ? 0 : int.Parse(dtCheckList.Rows[rowno]["ExtraItemNo7"].ToString());
            int ExtraChecklistItemID8 = string.IsNullOrEmpty(dtCheckList.Rows[rowno]["ExtraItemNo8"].ToString()) ? 0 : int.Parse(dtCheckList.Rows[rowno]["ExtraItemNo8"].ToString());
            int ExtraChecklistItemID9 = string.IsNullOrEmpty(dtCheckList.Rows[rowno]["ExtraItemNo9"].ToString()) ? 0 : int.Parse(dtCheckList.Rows[rowno]["ExtraItemNo9"].ToString());
            int ExtraChecklistItemID10 = string.IsNullOrEmpty(dtCheckList.Rows[rowno]["ExtraItemNo10"].ToString()) ? 0 : int.Parse(dtCheckList.Rows[rowno]["ExtraItemNo10"].ToString());

            if (ExtraChecklistItemID1 != 0)
                hdnExtraItem1.Value = ExtraChecklistItemID1.ToString();
            if (ExtraChecklistItemID2 != 0)
                hdnExtraItem2.Value = ExtraChecklistItemID2.ToString();
            if (ExtraChecklistItemID3 != 0)
                hdnExtraItem3.Value = ExtraChecklistItemID3.ToString();
            if (ExtraChecklistItemID4 != 0)
                hdnExtraItem4.Value = ExtraChecklistItemID4.ToString();
            if (ExtraChecklistItemID5 != 0)
                hdnExtraItem5.Value = ExtraChecklistItemID5.ToString();
            if (ExtraChecklistItemID6 != 0)
                hdnExtraItem6.Value = ExtraChecklistItemID6.ToString();
            if (ExtraChecklistItemID7 != 0)
                hdnExtraItem7.Value = ExtraChecklistItemID7.ToString();
            if (ExtraChecklistItemID8 != 0)
                hdnExtraItem8.Value = ExtraChecklistItemID8.ToString();
            if (ExtraChecklistItemID9 != 0)
                hdnExtraItem9.Value = ExtraChecklistItemID9.ToString();
            if (ExtraChecklistItemID10 != 0)
                hdnExtraItem10.Value = ExtraChecklistItemID10.ToString();

            dt = VerificationChecklistHandler.GetExtraChecklistItem(ExtraChecklistItemID1, ExtraChecklistItemID2, ExtraChecklistItemID3, ExtraChecklistItemID4, ExtraChecklistItemID5, ExtraChecklistItemID6, ExtraChecklistItemID7, ExtraChecklistItemID8, ExtraChecklistItemID9, ExtraChecklistItemID10);
            return dt;
        }

        private void FillExtraItem1(DataTable dtCheckList)
        {
            DataTable dtExtraItem = setValueForHiddenField(dtCheckList, 0);

            int cntIncome = 0;
            int cntAssert = 0;
            int cntResidential = 0;
            int cntIDs = 0;
            foreach (DataRow dr in dtExtraItem.Rows)
            {
                if (dr["ItemType"].ToString() == "Income")
                {
                    if (hdnExtraItem1.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo1.Style.Remove("display");
                        chkExtraItemNo11.Checked = true;
                        lblExtraItemName1.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo11.Value = dr["ExtraChecklistItemID"].ToString();
                        cntIncome++;
                    }
                    else if (hdnExtraItem2.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo2.Style.Remove("display");
                        chkExtraItemNo21.Checked = true;

                        lblExtraItemName2.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo21.Value = dr["ExtraChecklistItemID"].ToString();
                        cntIncome++;
                    }
                    else if (hdnExtraItem3.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo3.Style.Remove("display");
                        chkExtraItemNo31.Checked = true;
                        lblExtraItemName3.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo31.Value = dr["ExtraChecklistItemID"].ToString();
                        cntIncome++;
                    }
                }
                else if (dr["ItemType"].ToString() == "Assert")
                {
                    if (hdnExtraItem4.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo4.Style.Remove("display");
                        chkExtraItemNo41.Checked = true;
                        lblExtraItemName4.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo41.Value = dr["ExtraChecklistItemID"].ToString();
                        cntAssert++;
                    }
                    else if (hdnExtraItem5.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo5.Style.Remove("display");
                        chkExtraItemNo51.Checked = true;
                        lblExtraItemName5.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo51.Value = dr["ExtraChecklistItemID"].ToString();
                        cntAssert++;
                    }
                    else if (hdnExtraItem6.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo6.Style.Remove("display");
                        chkExtraItemNo61.Checked = true;

                        lblExtraItemName6.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo61.Value = dr["ExtraChecklistItemID"].ToString();
                        cntAssert++;
                    }
                }
                else if (dr["ItemType"].ToString() == "Residential")
                {
                    if (hdnExtraItem7.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo7.Style.Remove("display");
                        chkExtraItemNo71.Checked = true;
                        lblExtraItemName7.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo71.Value = dr["ExtraChecklistItemID"].ToString();
                        cntResidential++;
                    }
                    else if (hdnExtraItem8.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo8.Style.Remove("display");
                        chkExtraItemNo81.Checked = true;

                        lblExtraItemName8.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo81.Value = dr["ExtraChecklistItemID"].ToString();
                        cntResidential++;
                    }
                }
                else if (dr["ItemType"].ToString() == "IDs")
                {
                    if (hdnExtraItem9.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo9.Style.Remove("display");
                        chkExtraItemNo91.Checked = true;

                        lblExtraItemName9.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo91.Value = dr["ExtraChecklistItemID"].ToString();
                        cntIDs++;
                    }
                    else if (hdnExtraItem10.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo10.Style.Remove("display");
                        chkExtraItemNo101.Checked = true;

                        lblExtraItemName10.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo101.Value = dr["ExtraChecklistItemID"].ToString();
                        cntIDs++;
                    }
                }
            }
        }
        private void FillExtraItem2(DataTable dtCheckList)
        {
            DataTable dtExtraItem = setValueForHiddenField(dtCheckList, 1);

            int cntIncome = 0;
            int cntAssert = 0;
            int cntResidential = 0;
            int cntIDs = 0;
            foreach (DataRow dr in dtExtraItem.Rows)
            {
                if (dr["ItemType"].ToString() == "Income")
                {
                    if (hdnExtraItem1.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo1.Style.Remove("display");
                        chkExtraItemNo12.Checked = true;

                        lblExtraItemName1.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo12.Value = dr["ExtraChecklistItemID"].ToString();
                        cntIncome++;
                    }
                    else if (hdnExtraItem2.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo2.Style.Remove("display");
                        chkExtraItemNo22.Checked = true;

                        lblExtraItemName2.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo22.Value = dr["ExtraChecklistItemID"].ToString();
                        cntIncome++;
                    }
                    else if (hdnExtraItem3.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo3.Style.Remove("display");
                        chkExtraItemNo32.Checked = true;

                        lblExtraItemName3.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo32.Value = dr["ExtraChecklistItemID"].ToString();
                        cntIncome++;
                    }
                }
                else if (dr["ItemType"].ToString() == "Assert")
                {
                    if (hdnExtraItem4.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo4.Style.Remove("display");
                        chkExtraItemNo42.Checked = true;

                        lblExtraItemName4.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo42.Value = dr["ExtraChecklistItemID"].ToString();
                        cntAssert++;
                    }
                    else if (hdnExtraItem5.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo5.Style.Remove("display");
                        chkExtraItemNo52.Checked = true;

                        lblExtraItemName5.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo52.Value = dr["ExtraChecklistItemID"].ToString();
                        cntAssert++;
                    }
                    else if (hdnExtraItem6.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo6.Style.Remove("display");
                        chkExtraItemNo62.Checked = true;

                        lblExtraItemName6.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo62.Value = dr["ExtraChecklistItemID"].ToString();
                        cntAssert++;
                    }
                }
                else if (dr["ItemType"].ToString() == "Residential")
                {
                    if (hdnExtraItem7.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo7.Style.Remove("display");
                        chkExtraItemNo72.Checked = true;

                        lblExtraItemName7.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo72.Value = dr["ExtraChecklistItemID"].ToString();
                        cntResidential++;
                    }
                    else if (hdnExtraItem8.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo8.Style.Remove("display");
                        chkExtraItemNo82.Checked = true;

                        lblExtraItemName8.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo82.Value = dr["ExtraChecklistItemID"].ToString();
                        cntResidential++;
                    }
                }
                else if (dr["ItemType"].ToString() == "IDs")
                {
                    if (hdnExtraItem9.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo9.Style.Remove("display");
                        chkExtraItemNo92.Checked = true;

                        lblExtraItemName9.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo92.Value = dr["ExtraChecklistItemID"].ToString();
                        cntIDs++;
                    }
                    else if (hdnExtraItem10.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo10.Style.Remove("display");
                        chkExtraItemNo102.Checked = true;

                        lblExtraItemName10.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo102.Value = dr["ExtraChecklistItemID"].ToString();
                        cntIDs++;
                    }
                }
            }
        }
        private void FillExtraItem3(DataTable dtCheckList)
        {

            DataTable dtExtraItem = setValueForHiddenField(dtCheckList, 2);

            int cntIncome = 0;
            int cntAssert = 0;
            int cntResidential = 0;
            int cntIDs = 0;
            foreach (DataRow dr in dtExtraItem.Rows)
            {
                if (dr["ItemType"].ToString() == "Income")
                {
                    if (hdnExtraItem1.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo1.Style.Remove("display");
                        chkExtraItemNo13.Checked = true;

                        lblExtraItemName1.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo13.Value = dr["ExtraChecklistItemID"].ToString();
                        cntIncome++;
                    }
                    else if (hdnExtraItem2.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo2.Style.Remove("display");
                        chkExtraItemNo23.Checked = true;

                        lblExtraItemName2.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo23.Value = dr["ExtraChecklistItemID"].ToString();
                        cntIncome++;
                    }
                    else if (hdnExtraItem3.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo3.Style.Remove("display");
                        chkExtraItemNo33.Checked = true;

                        lblExtraItemName3.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo33.Value = dr["ExtraChecklistItemID"].ToString();
                        cntIncome++;
                    }
                }
                else if (dr["ItemType"].ToString() == "Assert")
                {
                    if (hdnExtraItem4.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo4.Style.Remove("display");
                        chkExtraItemNo43.Checked = true;

                        lblExtraItemName4.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo43.Value = dr["ExtraChecklistItemID"].ToString();
                        cntAssert++;
                    }
                    else if (hdnExtraItem5.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo5.Style.Remove("display");
                        chkExtraItemNo53.Checked = true;

                        lblExtraItemName5.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo53.Value = dr["ExtraChecklistItemID"].ToString();
                        cntAssert++;
                    }
                    else if (hdnExtraItem6.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo6.Style.Remove("display");
                        chkExtraItemNo63.Checked = true;
                        lblExtraItemName6.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo63.Value = dr["ExtraChecklistItemID"].ToString();
                        cntAssert++;
                    }
                }
                else if (dr["ItemType"].ToString() == "Residential")
                {
                    if (hdnExtraItem7.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo7.Style.Remove("display");
                        chkExtraItemNo73.Checked = true;

                        lblExtraItemName7.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo73.Value = dr["ExtraChecklistItemID"].ToString();
                        cntResidential++;
                    }
                    else if (hdnExtraItem8.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo8.Style.Remove("display");
                        chkExtraItemNo83.Checked = true;

                        lblExtraItemName8.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo83.Value = dr["ExtraChecklistItemID"].ToString();
                        cntResidential++;
                    }
                }
                else if (dr["ItemType"].ToString() == "IDs")
                {
                    if (hdnExtraItem9.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo9.Style.Remove("display");
                        chkExtraItemNo93.Checked = true;

                        lblExtraItemName9.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo93.Value = dr["ExtraChecklistItemID"].ToString();
                        cntIDs++;
                    }
                    else if (hdnExtraItem10.Value == dr["ExtraChecklistItemID"].ToString())
                    {
                        trExtraItemNo10.Style.Remove("display");
                        chkExtraItemNo103.Checked = true;

                        lblExtraItemName10.Text = dr["ItemName"].ToString();
                        hdnExtraItemNo103.Value = dr["ExtraChecklistItemID"].ToString();
                        cntIDs++;
                    }
                }
            }
        }


    }
}